// ---------------------COMMENT------------------------
var Comment = require('../models/comment');

exports.save = function (req, res) {
  var _comment = req.body.comment;
  var movieId = _comment.movie;

  if (_comment.cid) { // 评论它人时 - 追加被评论人id信息
    Comment.findById(_comment.cid, function(err, comment) {
      var reply = {
        from: _comment.from,
        to: _comment.tid,
        content: _comment.content
      };

      comment.reply.push(reply);

      comment.save(function (err, comment) {
        if (err) {
          console.log(err.code, err.message);
        }
        res.redirect('/movie/' + movieId);
      });
    });
  } else { // 个人评论
    var comment = new Comment(_comment);
    comment.save(function (err, comment) {
      if (err) {
        console.log(err.code, erro.message);
      }
      res.redirect('/movie/' + movieId);
    });
  }
};
